<!doctype html>
<html lang="en" class="no-js">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
    
<link href="css/boot.css" rel='stylesheet' type='text/css'>
<link href="css/thecompany.css" rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=PT+Sans:400,700' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=PT+Sans:400,700' rel='stylesheet' type='text/css'>

	<link rel="stylesheet" href="css/reset.css"> <!-- CSS reset -->
	<link rel="stylesheet" href="css/style.css"> <!-- Gem style -->
	<script src="js/modernizr.js"></script> <!-- Modernizr -->

 <style type="text/css">
	#tfheader{
		background-color:#c3dfef;
	}
	#tfnewsearch{
		float:right;
		padding:20px;
	}
	.tftextinput{
		margin: 0;
		padding: 5px 15px;
		font-family: Arial, Helvetica, sans-serif;
		font-size:14px;
		border:1px solid #0076a3; border-right:0px;
		border-top-left-radius: 5px 5px;
		border-bottom-left-radius: 5px 5px;
	}
	.tfbutton {
		margin: 0;
		padding: 5px 15px;
		font-family: Arial, Helvetica, sans-serif;
		font-size:14px;
		outline: none;
		cursor: pointer;
		text-align: center;
		text-decoration: none;
		color: #ffffff;
		border: solid 1px #0076a3; border-right:0px;
		background: #0095cd;
		background: -webkit-gradient(linear, left top, left bottom, from(#00adee), to(#0078a5));
		background: -moz-linear-gradient(top,  #00adee,  #0078a5);
		border-top-right-radius: 5px 5px;
		border-bottom-right-radius: 5px 5px;
	}
	.tfbutton:hover {
		text-decoration: none;
		background: #007ead;
		background: -webkit-gradient(linear, left top, left bottom, from(#0095cc), to(#00678e));
		background: -moz-linear-gradient(top,  #0095cc,  #00678e);
	}
	/* Fixes submit button height problem in Firefox */
	.tfbutton::-moz-focus-inner {
	  border: 0;
	}
	.tfclear{
		clear:both;
	}
</style>

<script>

function validatesignupform() {
    var x = document.myform2.signuser.value;
    var y = document.myform2.signpass.value;
	var z = document.myform2.signemail.value;

	
	if (x == null || x == "") {
        alert("Username must be filled out");
        return false;
    }
	
	if(z == null || z == "")
	{
	  	alert("Email must be filled out");
        return false;	
	}	

	if(y == null || y == "")
	{
	 	alert("Password must be filled out");
     	return false;	
	}	
	if(document.myform2.trm.checked == false)
	{
	alert("Please check the term and agreements");
    return false;	
	}	
	return (true);
	
}

function validatelogform(){
	
	
	var x = document.myform.username.value;
    var y = document.myform.password.value;
	
	
	if (x == null || x == "") {
        alert("Username must be filled out");
        return false;
    }
	
	if(y == null || y == "")
	{
	 	alert("Password must be filled out");
     	return false;	
	}	
	return (true);
	}
</script>


<?php

include __DIR__ ."../PHP/db.php";
	
if ($_SESSION['login'] != NULL)
{	
	$getdata = $_SESSION['login'];
	$user = mysql_fetch_array(mysql_query("SELECT * FROM `flss`.`accounts` WHERE `user`='$getdata'"));
	
	$getlevelofuser = $user['level_no'];
	if ($getlevelofuser == '2')
	{
		header("Location: Employer/employer.php");
	}
	else if ($getlevelofuser == '3')
	{
		header("Location: applicant/index.php");
	}
}
else
{
								
error_reporting(0);

if($_POST['loginbutton'])
{
		if($_POST['username'] && $_POST['password'])
		{
			$username = mysql_real_escape_string($_POST['username']);
			$password = md5($_POST['password']);
			$user = mysql_fetch_array(mysql_query("SELECT * FROM `accounts` WHERE `user`='$username'"));
			if ($user == '0')
			{	echo '<script type="text/javascript">alert("User is not registered");</script>';
			
				}
			else{
					if ($user['pass'] != $password){
					print '<script type="text/javascript">
							alert("Incorrect type of combination"); 
							document.myform.password.focus();
     					 </script>';
						}
					else
					{
						if($user['level_no'] == '2')
							{
								if(isset($_POST['loginbutton']))
								{

								$_SESSION['login'] = $_POST['username'];
								header("location: Employer/employer.php"); 
								exit();
								}
							
								else
								{
								}
							}
						else if($user['level_no'] == '3')
							{
							if(isset($_POST['loginbutton']))
								{

								$_SESSION['login'] = $_POST['username'];
								header("location: applicant/index.php");
								exit();
							
								}
							
								else
								{
								}
						
							}
						else
							{
							header("location: admin/adminpage.html");
							
							}
			
	
					}
					
				}	
		}
	} 
 
else if($_POST['signbutton'])
{
		if($_POST['signuser'] && $_POST['signpass'])
		{
			$signusername = mysql_real_escape_string($_POST['signuser']);
			$signpassword = md5($_POST['signpass']);
			$signemail = $_POST['signemail'];
			
			$check = mysql_fetch_array(mysql_query("SELECT * FROM `accounts` WHERE `user`='$signusername'"));
			$checkemail = mysql_fetch_array(mysql_query("SELECT `emailadd` FROM `accounts` WHERE `emailadd`='$signemail'"));
			if ($check != '0')
			{	echo '<script type="text/javascript">alert("Username was already used");</script>';
			}
			else
			{
				if ($checkemail != '0')
				{	echo '<script type="text/javascript">alert("Email was already used");</script>';
				}
				else
				{
					if(!ctype_alnum($signusername)){
					echo '<script type="text/javascript">alert("Username contains invalid character");</script>';
					}
					else
					{
						if (strlen($signusername) > 20){
						echo '<script type="text/javascript">alert("Username exceeds to 20 character");</script>';
						}
						else
						{
							$empl = '';
							if ($_POST['emp'] == 'checked')
							{	$empl = 2;
							$refid = uniqid();
							mysql_query("INSERT INTO `flss`.`accounts` (`account_id`, `level_no`, `user`, `pass`, `emailadd`) VALUES (NULL, '$empl', '$signusername', '$signpassword', '$signemail') ") or die(mysql_error());
							$accid = mysql_fetch_array(mysql_query("SELECT `account_id` FROM `flss`.`accounts` WHERE `user`='$signusername'"));
							$containaccount = $accid['account_id'];
							mysql_query("INSERT INTO `flss`.`employer` (`employer_id`, `e_statusid`, `ename`, `e_address`, `contact`, `email`, `description`, `whyjoinus`, `refid`) VALUES ('$containaccount', '1', 'Company Name', '', '', '$signemail', '', '' , '$refid')") or die(mysql_error());
							mysql_query("INSERT INTO `flss`.`e_archives` (`employer_id`, `e_status`, `datestart`, `datelast`) VALUES ('$containaccount', '', '', '')");
							mysql_query("INSERT INTO `flss`.`e_snap` (`e_id`, `Registration_No`, `Industry`, `Company_size`, `Working_hours`, `Dresscode`, `Benefits`, `Spoken_language`) 
							VALUES ('$containaccount', '', '', '', '', '', '', '')");
									
							}
							else
							{	$empl = 3;
								$refida = uniqid();
								mysql_query("INSERT INTO `flss`.`accounts` (`account_id`, `level_no`, `user`, `pass`, `emailadd`) VALUES (NULL, '$empl', '$signusername', '$signpassword', '$signemail') ") or die(mysql_error());
								$accid = mysql_fetch_array(mysql_query("SELECT `account_id` FROM `flss`.`accounts` WHERE `user`='$signusername'"));
								$containaccount = $accid['account_id'];
								mysql_query("INSERT INTO `flss`.`applicant` (`applicant_id`, `a_status`, `fname`, `mname`, `lname`,
								`a_address`, `city`, `country`, `email`, `age`, `gender`, `tel`, `mobile`, `civilstatus`, `religion`, `dob`,
								`pob`, `children`, `weight`, `height`, `nationality`, `mother`, `father`, `job_id`, `photo`, `refid`) 
								VALUES ('$containaccount', '1', '', '', '', '', '', '$signemail',
								'', '', '', '', '', '', '', '', '', '', '', '', '', '',
								'', '', '','$refida')") or die(mysql_error());
								mysql_query("INSERT INTO `flss`.`applicant_archives` (`applicant_id`, `a_status`, `datestart`, `datelast`) VALUES ('$containaccount', '', '', '')");
								mysql_query("INSERT INTO `flss`.`a_address` (`applicant_id`, `a_address`, `city`, `country`, `Street`) VALUES ('$containaccount', '', '', '', '')");
							}
							
							echo '<script type="text/javascript">alert("Account successfully created please do log in");</script>';
						}
					}
				}
			}
		}	
	} 
 
}
 ?>	
    
    
	<title>FLSS</title>
</head>
<body>
	<header role="banner">
		<div id="cd-logo"><a href="#"><img src="images/logo.png" alt="Logo"></a></div>

		<nav class="main-nav">
			<ul>
				<!-- inser more links here -->
				<li><a class="cd-signin" href="#0" ><font size="+2"> Sign in</a></li>
				<li><a class="cd-signup" href="#0" >Sign up</a></li>
                </font>
			</ul>
		</nav>
	</header>

	<div class="cd-user-modal"> <!-- this is the entire modal form, including the background -->
		<div class="cd-user-modal-container"> <!-- this is the container wrapper -->
			<ul class="cd-switcher">
				<li><a href="#0">Sign in</a></li>
				<li><a href="#0">New account</a></li>
			</ul>
<!-- get data -->
			<div id="cd-login"> <!-- log in form -->
				<form class="cd-form" action='' method="post" name="myform" onsubmit="return (validatelogform())">
					<p class="fieldset">
						<label class="image-replace cd-username" for="signin-username">Username</label>
						<input class="full-width has-padding has-border" name="username" id="signup-username" type="text" placeholder="Username" required>
						<span class="cd-error-message">Error message here!</span>
					</p>

					<p class="fieldset">
						<label class="image-replace cd-password" for="signin-password">Password</label>
						<input class="full-width has-padding has-border" name="password" id="signin-password" type="text"  placeholder="Password" required>
						<a href="#0" class="hide-password">Hide</a>
						<span class="cd-error-message">Error message here!</span>
					</p>

					<p class="fieldset">
						<input type="checkbox" id="remember-me" checked>
						<label for="remember-me">Remember me</label>
					</p>

					<p class="fieldset">
						<input class="full-width" type="submit" name="loginbutton" value="Login">
					</p>
				</form>
				
				<p class="cd-form-bottom-message"><a href="#0">Forgot your password?</a></p>
				<!-- <a href="#0" class="cd-close-form">Close</a> -->
			</div> <!-- cd-login -->

			<div id="cd-signup"> <!-- sign up form -->
				<form class="cd-form" action='' method="post" name="myform2" onSubmit="return (validatesignupform())">
					<p class="fieldset">
						<label class="image-replace cd-username" for="signup-username">Username</label>
						<input class="full-width has-padding has-border"  name="signuser" id="signup-username" type="text" placeholder="Username" required>
						<span class="cd-error-message">Error message here!</span>
					</p>

					<p class="fieldset">
						<label class="image-replace cd-email" for="signup-email">E-mail</label>
						<input class="full-width has-padding has-border" name="signemail" id="signup-email" type="email" placeholder="E-mail" required>
						<span class="cd-error-message">Error message here!</span>
					</p>

					<p class="fieldset">
						<label class="image-replace cd-password" for="signup-password">Password</label>
						<input class="full-width has-padding has-border" name="signpass" id="signup-password" type="text"  placeholder="Password" required>
						<a href="#0" class="hide-password">Hide</a>
						<span class="cd-error-message">Error message here!</span>
					</p>
                    
					<p class="fieldset">
						<input type="checkbox" class="chkBox" value="impchecked" name="trm" id="accept-terms" required>
						<label for="accept-terms">I agree to the <a href="#0">Terms</a></label>
						<label style="float:right;" for="employer"> check if you are an employer</label>
					<input style="float:right; margin-right:2px;" value="checked" name="emp" type="checkbox" id="employer" >
						
                    </p>

					<p class="fieldset">
						<input class="full-width has-padding" type="submit" name="signbutton" value="Create account">
					</p>
				</form>

				<!-- <a href="#0" class="cd-close-form">Close</a> -->
			</div> <!-- cd-signup -->

			<div id="cd-reset-password"> <!-- reset password form -->
				<p class="cd-form-message">Lost your password? Please enter your email address. You will receive a link to create a new password.</p>

				<form class="cd-form">
					<p class="fieldset">
						<label class="image-replace cd-email" for="reset-email">E-mail</label>
						<input class="full-width has-padding has-border" name="resetemail" id="reset-email" type="email" placeholder="E-mail" required>
						<span class="cd-error-message">Error message here!</span>
					</p>

					<p class="fieldset">
						<input class="full-width has-padding" type="submit" value="Reset password">
					</p>
				</form>

				<p class="cd-form-bottom-message"><a href="#0">Back to log-in</a></p>
			</div> <!-- cd-reset-password -->
			<a href="#0" class="cd-close-form">Close</a>
		</div> <!-- cd-user-modal-container -->
	</div> <!-- cd-user-modal -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="js/main.js"></script> <!-- Gem jQuery -->

<link href="jQueryAssets/jquery.ui.core.min.css" rel="stylesheet" type="text/css">
<link href="jQueryAssets/jquery.ui.theme.min.css" rel="stylesheet" type="text/css">
<link href="jQueryAssets/jquery.ui.accordion.min.css" rel="stylesheet" type="text/css">
<script src="jQueryAssets/jquery-1.8.3.min.js" type="text/javascript"></script>
<script src="jQueryAssets/jquery-ui-1.9.2.accordion.custom.min.js" type="text/javascript"></script>
<div style="width:100%; margin-top:100px;">
<div style="width:70%; margin-left:auto; margin-right:auto;">
<!--search query here-->

</div>
</div>

<div class="search-container" style="position:relative; margin-top:70px; margin-left: 222px; margin-right: 200px;">
	<div id="tfheader">
		<form id="tfnewsearch" method="get" action="">
		        <input type="text" placeholder="Keywords, Title, Categories, Subcategories" class="tftextinput" name="qwertyuiop" size="100" maxlength="120"><input type="submit" value="search" class="tfbutton">
		</form>
	<div class="tfclear"></div>
</div>
	<div class="search-header">
		<h4>Job Search Query</h4>
		<hr><hr>
	</div>
	<div>
		<table width=100%>
			<tr>
			<th>Job title</th>
			<th>Company</th>
			<th>Applicant Needed</th>
			<th>Minimum Yrs Experience</th>
			<th>Date Posted</th>
			</tr>
            <?php 
			$keyword = $_GET['qwertyuiop'];
			$getalljobs = mysql_query("SELECT em.ename as name, jo.Title as title, jo.numapps as numb, jo.date_posted as date, jo.Job_mined as educ, jo.refid as refid, jo.job_id as id
			FROM job_order jo
			LEFT JOIN employer em on em.employer_id = jo.employer_id
			WHERE (jo.Title LIKE '%$keyword%' OR jo.Job_category LIKE '%$keyword%' OR jo.Job_sub LIKE '%$keyword%') AND  jo.status = '1'
			") or die(mysql_error());

			while($rowapp = mysql_fetch_array($getalljobs)) { 
			?>
			<tr id="id_<?=$rowapp['id']?>">
				<td width="35%"><a style="cursor:pointer;" href="Employer/Job/joborder.php?refid=<?=$rowapp['refid']?>" onClick="window.open(this.href,'popupwindow','left=200,top=50,width=1000,height=600,scrollbars=yes,menu=0,status=0'); return false;"> 
                				<?=$rowapp['title']?>
                                </a>
                </td>
				<td width="20%"><?=$rowapp['name']?></td>
				<td width="10%"><?=$rowapp['numb']?></td>
				<td width="15%" align="left"><?=$rowapp['educ']?></td>
				<td width="20%"><?=$rowapp['date']?></td>	
			</tr>
            <tr>
            <td>
            <hr>
            </td>
            </tr>
			
            <?php } ?>
		</table>
	</div>
</div>
<br><br><br>
<center><p class="copyright">© 2015 Famous Labour Supply Services</p></center>



    <script type="text/javascript">
    $(function(){
    	$(document).ready(function(){
    		$('#employer').change(function() {
			   if($(this).is(":checked")) {
			      //'checked' event code
			      alert('try');
			      //hide
			      $('#employer_div').show();
			      return;
			   }
			   //'unchecked' event code
			   	  $('#employer_div').hide();
			});
    	});
    });
    	
    </script>

</body>
</html>